using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;


namespace _7TC056_QuanLyNhaSach.HeThongLuuTru
{
    class DataAccess
    {
        protected static String _connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=QLNS.mdb"; 
        static OleDbConnection connection;
 
        public static void OpenConnection()
        {
            try
                {  connection = new OleDbConnection(_connectionString); 
                   connection.Open();
                } 
            catch (Exception ex)
                {
                }
       }
        public static void CloseConnection()
        {
            if (connection != null)
            {
                connection.Close();
            }
        }
        public static DataTable ExecQuery(string sql)
        {
            OpenConnection();
            DataTable dt = new DataTable();
            OleDbCommand command = connection.CreateCommand();
            command.CommandText = sql;
            OleDbDataAdapter adt = new OleDbDataAdapter();
            adt.SelectCommand = command;
            adt.Fill(dt);
            CloseConnection();
            return dt;
        }
        public static void ExecNonQuery(string sql)
        {
            OpenConnection();
            OleDbCommand com = connection.CreateCommand();
            com.CommandText = sql;
            com.ExecuteNonQuery();
        }
    }
}
